package cn.zh.controller;

import cn.hutool.core.util.IdUtil;
import cn.zh.annotations.LogOperation;
import cn.zh.commons.ResponseResult;
import cn.zh.entity.Order;
import cn.zh.enums.OperationType;
import cn.zh.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author : 张航
 * @date : 2024-05-30 15:12
 * @description:
 **/
@RestController
@RequestMapping("order")
public class OrderController {
    @Resource
    private OrderService orderService;
    @RequestMapping("page")
    public ResponseResult orderPage(Integer page ,Integer limit,String orderId){
        return orderService.orderPage(page,limit,orderId);

    }
    @LogOperation(model = "订单模块",operation = OperationType.UPDATE)
    @RequestMapping("delete")
    public ResponseResult deleteOrder(Integer[] ids){
        return orderService.deleteOrder(ids);

    }
    @LogOperation(model = "订单模块",operation = OperationType.UPDATE)
    @RequestMapping("edit")
    public ResponseResult editOrder(Integer id){
        return orderService.editOrder(id);

    }
    @LogOperation(model = "订单模块",operation = OperationType.UPDATE)
    @RequestMapping("noedit")
    public ResponseResult noEditOrder(Integer id){
        return orderService.noEditOrder(id);

    }


    @RequestMapping("add")
    public ResponseResult addOrder(Order order, HttpServletRequest request){
        HttpSession session = request.getSession();
        String tenement =(String) session.getAttribute("tenement");
        String renting =(String) session.getAttribute("renting");
        String createTime = (String) session.getAttribute("createTime");


        StringBuffer stringBuffer=new StringBuffer();
        stringBuffer.append(tenement);
        stringBuffer.append(renting);
        stringBuffer.append(createTime);

        order.setOrderId(stringBuffer.toString());

        return orderService.addOrder(order,request);
    }
}
